// pages/order/issue/issue.js
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status:1,
    statusActive:1,
	orderid:0,
    longitude:'104.084755',
    latitude:'30.629854',
    orderStatus:2,
	quotelist:[],   
	login:0,
	token:'',
    markers:[
      {
        id:7,
        latitude:'30.62875',
        longitude:'104.08397',
        iconPath:'../../../static/images/site.png',
        width:'32rpx',
        height:'32rpx',
        callout:{
          content:'点击获得最新报价通知>',
          color:'#fa8333',
          fontSize:'12',
          bgColor:'#fff',
          borderRadius:15,
          padding:10,
          display:'ALWAYS'
        }
      }
    ],
    isShow:false
  },
  getTabs(e){
    this.setData({
      statusActive:Number(e.currentTarget.dataset.type)
    })
  },
  getPay(e){
	   var amount = e.currentTarget.dataset.amount;
	   var serviceid = e.currentTarget.dataset.id;
	    var orderid = e.currentTarget.dataset.orderid;
	  var that = this;
	  let param = {
	    scoure: 'wxapp',
	    token: that.data.token,
	    order_id: orderid,
		service_id:serviceid,
		service_amount:amount 
	  }
	   console.log('====')
	  console.log(url.updateorderamount) 
	  wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
	  request.request(url.updateorderamount, param, url.REQUEST_METHOD_GET).then((res) => {
	    wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
	    console.log(res.data.code);
	    if (res.data.code == 1) {
			wx.navigateTo({ 
			 url: '../../user_end/order_choose/order_choose?id=' + orderid,
			})
	    }
	  })
	  
    // wx.navigateTo({
    //   url: '/pages/order/pay/pay',
    // })
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
	  console.log(options)
	 this.setData({
		  orderid: options.id
		})
		var that = this;
		cookie.getCookie('userInfo', function (res) {
			
		  if (res) {
		    var etime = Date.parse(new Date()) / 1000;
		    
		    if (etime < res.expiretime) {
		      that.setData({
		        login: 1,
		        token: res.token
		      })
			 
		      that.getQuotelist();
		    }
		  }
		})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 var that = this;
    if (that.data.token) {
      that.getQuotelist();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  changeIshow(){
    this.setData({
      isShow:!this.data.isShow
    })
  },
  getQuotelist() {  
    var that = this;
    let param = {
      scoure: 'wxapp',
      token: that.data.token,
      order_id: that.data.orderid
    }
	 console.log('====')
	console.log(url.quotelist) 
    wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
    request.request(url.quotelist, param, url.REQUEST_METHOD_GET).then((res) => {
      wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
	  console.log(res);
      if (res.data.code == 1) {
        that.setData({ 
          quotelist: res.data.data
        })
      }
    })
  },
  cancelOrder(e) {
	var that = this;
    var id =that.data.orderid;
    var that = this;
    let param = {
      scoure: 'wxapp',
      token: that.data.token,
      id: id
    }
    wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
    request.request(url.cancelorder, param, url.REQUEST_METHOD_GET).then((res) => {
      wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
      wx.showToast({
        title: res.data.msg,
        icon: "none"
      })
	  wx.navigateTo({
	    url: '/pages/user_end/order/order'
	  })
	  
      if (res.data.code == 1) {
		  wx.navigateTo({
		    url: '/pages/user_end/order/order'
		  })
      }
    })
  },
})